package com.nwpu.bigdata.util.impl;



import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import com.nwpu.bigdata.service.impl.PodInfoServiceImpl;
import com.nwpu.bigdata.util.KubernetesUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;

/**
 *@version:2018年6月11日下午4:01:14
*/
/**
 * @author Administrator
 *
 */
@Configuration
@ImportResource(locations= {"classpath:/xmlConfig/spring/applicationContext-util.xml"})
public class KubernetesUtilImpl implements KubernetesUtil {
	@Value("${namespace}")
	private  String namespace;
    
	@Value("${kubernetes.url}")
	private  String url;

	private static final Logger logger = LoggerFactory.getLogger(PodInfoServiceImpl.class);
	@Override
	public  KubernetesClient connectK8s(){
	    
	    KubernetesClient client=null;
	    Config config = new ConfigBuilder().withMasterUrl(url)
	            .withTrustCerts(true)
	            .withNamespace(namespace).build();
	    try {
	    client = new DefaultKubernetesClient(config);
	        
	    }catch (Exception e) {
	           logger.error(e.getMessage(),e);
	    }
	    return  client;
	}
}
